﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Spring.Data.NHibernate.Generic.Support;
using NHibernate.Linq;
using System.Linq.Expressions;

namespace Ld.Server.Dao.Implement
{
    public abstract class RepositoryBase<T> : HibernateDaoSupport, IRepository<T> where T : class
    {
        public virtual object Save(T entity)
        {
            return this.HibernateTemplate.Save(entity);
        }

        public virtual T Get(object id)
        {
            return this.HibernateTemplate.Get<T>(id);
        }

        public virtual T Load(object id)
        {
            return this.HibernateTemplate.Load<T>(id);
        }

        public virtual IQueryable<T> LoadAll()
        {
            var result = Session.Linq<T>();
            return result;
        }

        public virtual void Update(T entity)
        {
            this.HibernateTemplate.Update(entity);
        }

        public void Delete(T entity)
        {
            this.HibernateTemplate.Delete(entity);
        }

        public virtual void SaveOrUpdate(T entity)
        {
            this.HibernateTemplate.SaveOrUpdate(entity);
        }

    }
}
